<?php
    $text=$_POST['text'];
    
    $checktext = str_replace(array("\r\n", "\r", "\n"), "", $text);

    if(isset($_POST['text']) && $checktext != '' && $text != ''){
        upload($text);
        $rawjson = array("code" => 0 , "data" => array("msg" => '提交成功!',"raw"=>$text));
        $json = json_encode($rawjson , JSON_UNESCAPED_UNICODE);
        echo $json;
    }

    else{
        $rawjson = array("code" => 1 , "data" => array("msg" => '提交内容为空, 请检查提交内容',"raw"=>$text));
        $json = json_encode($rawjson , JSON_UNESCAPED_UNICODE);
        echo $json;
    }

    function upload($text)
    {
        include './config/database.php';
        $con = mysqli_connect($dbhost,$dbuser,$dbpasswd,$dbname);
        $dbaa = $dbprefix."messages";
        $sql = "INSERT INTO `mht_messages` (`msg`) VALUES ('".$text."');";
        mysqli_query($con,$sql);
    }

?>